define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/shoporder/index',
                    //add_url: 'shop/shoporder/add',
                    edit_url: 'shop/shoporder/edit',
                    del_url: 'shop/shoporder/del',
                    //multi_url: 'shop/shoporder/multi',
                    table: 'shop_order'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                search:false,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no')},
                        {field: 'order_name', title: __('Order_name')},
                        //{field: 'user_id', title: __('User_id')},
                        //{field: 'coupon_id', title: __('Coupon_id')},
                        {field: 'contact', title: __('Contact')},
                        //{field: 'orig_price', title: __('Orig_price')},
                        {field: 'payment_price', title: __('Payment_price'),operate:false},
                        {field: 'create_time', title: __('Create_time'), formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'payment_time', title: __('Payment_time'), formatter: Table.api.formatter.datetime,operate:false},

                        //{field: 'status_text', title: __('Status'), searchList: Config.statusList, style: 'min-width:100px;'},
                        //{field: 'status', title: __('Status'), searchList: Config.statusList, style: 'min-width:100px;'},
                        {field: 'status', title: __('Status'), formatter: function(value){
                            return Config.statusList[value];
                        },searchList: Config.statusList, style: 'min-width:100px;'},

                        {field: 'id', title: __('Operate'), table: table, buttons: [
                            {
                                name: 'detail',
                                text: __('Detailed_list'),
                                title: __('Detailed_list'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-xs btn-success btn-dialog', url: 'shop/shoporder/detail'},
                            {
                                name: 'detail',
                                text: __('Deliver_goods'),
                                title: __('Deliver_goods'),
                                icon: 'fa fa-truck',
                                classname: 'btn btn-xs btn-info btn-dialog', url: 'shop/shoporder/send'},
                            {
                                name: 'detail',
                                text: __('Edit'),
                                title: __('Edit'),
                                icon: 'fa fa-edit',
                                classname: 'btn btn-xs btn-primary btn-dialog', url: 'shop/shoporder/edit'}
                        ], events: Table.api.events.operate, formatter: Table.api.formatter.buttons,operate:false}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        send: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});